from flask import Blueprint,request
from app.service.common_insert_service import CommonInsertSerevice
from utils.response_utils import ResponseUtils
from service.collection_service import CollectionService


insert_comment = Blueprint('insert_comment', __name__)

@insert_comment.route('/comment', methods=['POST'])
def def_insert_comment():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("comment",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)

@insert_comment.route('/submit_reply', methods=['POST'])
def sub_comment():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("sub_comment",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@insert_comment.route('/comment_likes', methods=['POST'])
def comment_likes():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("comment_likes",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@insert_comment.route('/note_likes', methods=['POST'])
def note_likes():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("note_likes",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@insert_comment.route('/note_collections', methods=['POST'])
def note_collections():
    try:
        count = CollectionService.check_is_collection(request)
        print('count',count)
        if count['count'] > 0:
            return ResponseUtils.success(data={'isCollection': True}, message='已经收藏过了', code=200)
        res = CommonInsertSerevice.insert_item_by_arg("collections",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
## 自己发布文章自己默认关注
@insert_comment.route('/note_collections_stauts', methods=['POST'])
def note_collections_stauts():
    try:
        count = CollectionService.check_is_collection(request)
        print('count',count)
        if count['count'] > 0:
            return ResponseUtils.success(data={'isCollection': True}, message='已经收藏过了', code=200)
        return ResponseUtils.success(data={'isCollection': False})
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@insert_comment.route('/note_collection_cancel', methods=['POST'])
def note_collection_cancel():
    try:
        res = CollectionService.cancel_collection(request)
        return ResponseUtils.success(data=res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@insert_comment.route('/note_slide_imgs', methods=['POST'])
def note_slide_imgs():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("slide_imgs",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    

@insert_comment.route('/note_map_info', methods=['POST'])
def note_map_info():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("map_info",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    

@insert_comment.route('/note_follows', methods=['POST'])
def note_follows():
    try:
        res = CommonInsertSerevice.insert_item_by_arg("follows",request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)